package com.example.lenovo.demo.presenter.adapter;

import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.lenovo.demo.CityActivity;
import com.example.lenovo.demo.R;
import com.example.lenovo.demo.model.databean.CityBean;
import com.example.lenovo.demo.model.databean.ModelDaysBean;
import com.example.lenovo.demo.model.idatabean.OnCityClickSuccess;

import java.util.List;

/**
 * Created by Lenovo on 2017/1/11.
 */

public class CityActivityLvItemLvAdapter extends BaseAdapter {
    private List<ModelDaysBean.DataBean.DaysBean.PointsBean> data;
    private String city;
    private Context context;
    private String msg;
    private String num;
    private OnCityClickSuccess onCityClickSuccess;


    public CityActivityLvItemLvAdapter(List<ModelDaysBean.DataBean.DaysBean.PointsBean> data, Context context, String city, String msg, String num, OnCityClickSuccess onCityClickSuccess) {
        this.data = data;
        this.context = context;
        this.city=city;
        this.msg=msg;
        this.num=num;
        this.onCityClickSuccess=onCityClickSuccess;
    }

    @Override
    public int getCount() {
        return data.size()+1;
    }

    @Override
    public int getItemViewType(int position) {
        if(position==0){
            return 0;
        }else {
            return 1;
        }

    }

    @Override
    public int getViewTypeCount() {
        return 2;
    }

    @Override
    public Object getItem(int i) {
        return data.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(final int i, View view, ViewGroup viewGroup) {
        final ViewHolder viewHolder;
        if(view==null){
            LayoutInflater inflater=LayoutInflater.from(context);
            viewHolder=new ViewHolder();
            if(getItemViewType(i)==0){
                view=inflater.inflate(R.layout.cityactivitylvheader,viewGroup,false);
                viewHolder.head= (TextView) view.findViewById(R.id.cityacticity_header_tv);
                viewHolder.button= (Button) view.findViewById(R.id.cityacticity_header_btn);
                view.setTag(viewHolder);
            }else {
                view= inflater.inflate(R.layout.cityhot_lv_item,viewGroup,false);
                viewHolder.tv1= (TextView) view.findViewById(R.id.cityhotlv_tv1);
                viewHolder.tv2= (TextView) view.findViewById(R.id.cityhotlv_tv2);
                viewHolder.includebtn= (Button) view.findViewById(R.id.cityac_lvitem_includebtn);
                viewHolder.includetv= (TextView) view.findViewById(R.id.cityac_lvitem_includemsg);
                viewHolder.linearLayout= (LinearLayout) view.findViewById(R.id.cityac_lvitem_includeLinearLayout);
                viewHolder.imageView= (ImageView) view.findViewById(R.id.cityac_lvitem_includeImg);
                viewHolder.cityhotlv_img= (ImageView) view.findViewById(R.id.cityhotlv_img);
                view.setTag(viewHolder);
            }

        }else {
            viewHolder= (ViewHolder) view.getTag();
        }
        if(i==0){
            viewHolder.head.setText(msg);
            viewHolder.button.setText("DAY"+(num)+"："+city);
            viewHolder.button.setTag(num);

            viewHolder.button.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    String a= (String) viewHolder.button.getTag();
                    onCityClickSuccess.CitySuccess(Integer.parseInt(a)-1);
                }
            });
        }else {
            ModelDaysBean.DataBean.DaysBean.PointsBean pointsBean=data.get(i-1);
            viewHolder.tv1.setText(pointsBean.getInspiration_activity().getTopic());
            viewHolder.tv2.setText(city+"•建议玩"+pointsBean.getInspiration_activity().getVisit_tip());
            viewHolder.includetv.setText(pointsBean.getInspiration_activity().getIntroduce());
            Glide.with(context).load(pointsBean.getInspiration_activity().getPhoto().getPhoto_url())
                    .into(viewHolder.imageView);

        }
        return view;
    }

    class ViewHolder{
        TextView tv1,tv2,head,includetv;
        Button button,includebtn;
        LinearLayout linearLayout;
        ImageView imageView,cityhotlv_img;

    }
}
